import { useTableColumnProps } from '/@/hooks/table-column/props'

/**
 * 显示部门名称, 单个或多个
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @param orgProp column.prop
 * @returns tableColumn props
 */
export function useTableColumnOrg<
  T extends Record<string, any>,
  D extends Record<string, any>,
  P extends keyof T
>(
  prop: P,
  label: string,
  options: UseTableColumnProps<any, T, P> = {},
  orgProp: keyof D = 'orgFullName'
) {
  return useTableColumnProps(prop, label, {
    width: 330,
    formatter: (row: T) => {
      let str
      switch (true) {
        case Array.isArray(row[prop]): {
          str = (row[prop] as D[]).map(item => item[orgProp]).join('，')
          break
        }
        case row[prop] && typeof row[prop] === 'object': {
          str = (row[prop] as D)[orgProp]
          break
        }
        default: {
          str = row[prop]
          break
        }
      }
      return str
    },
    ...options
  })
}
